package org.zwt.response.impl;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zwt.common.entity.HttpResponse;
import org.zwt.common.formatter.IResponseFormatter;
import org.zwt.response.IResponseHandler;

import java.io.IOException;
import java.io.OutputStream;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SimpleResponseHandler implements IResponseHandler {
    private IResponseFormatter responseFormatter;
    @Override
    public void handle(HttpResponse response, OutputStream os)throws IOException {
        /*
         *1.将HttpResponse对象，格式化为字符串
         **/
        String content = this.responseFormatter.format(response);
        /*
         *2.通过输出流，发送
         **/
        os.write(content.getBytes("UTF-8"));
        os.flush();
    }


}
